package patterns.iterator;

/**
 * Created by lenovo on 2016/11/30 0030.
 * Container的实现类，同时包含一个IIterator的内部实现类
 */
public class NameRepository implements IContainer{

    public String[] names = {"Robert","John","Julie","Lora"};
    @Override
    public IIterator getIterator() {
        return new NameIterator();
    }
    private class NameIterator implements IIterator{

        int index;
        @Override
        public boolean hasNext() {
            if (index<names.length){
                return true;
            }
            return false;
        }

        @Override
        public Object next() {
            if (this.hasNext()){
                return names[index++];
            }
            return null;
        }
    }
}
